<template>
  <div class="home">
    <Map></Map>
    <div class="content">
      <div class="content-top">
        <div :class="['content-top-tab', { 'content-top-tab-active': tab.componentName === currentTab.componentName }]" v-for="tab in tabs" @click="changeTab(tab)">{{ tab.label }}</div>
        <div class="content-top-blank"></div>
        <div class="content-top-quick">
          <div class="content-top-quick-botton" @click="saveGame">手动存档</div>
        </div>
      </div>
      <component :is="currentTab.componentName"></component>
    </div>
  </div>
</template>

<script>
import Map from '@/components/interface/Map.vue'
import Main from '@/components/content/Main.vue'
import Setting from '@/components/content/Setting.vue'
import About from '@/components/content/About.vue'

import Database from '@/game/database'

export default {
  name: 'Home',
  components: {
    Map,
    Main,
    Setting,
    About
  },
  data() {
    return {
      tabs: [{
          componentName: 'Main',
          label: '主界面'
        },
        {
          componentName: 'Setting',
          label: '设置'
        },
        {
          componentName: 'About',
          label: '关于'
        }
      ],
      currentTab: {
        componentName: 'Main',
        label: '主界面'
      }
    }
  },

  computed: {
    updateCount() {
      return this.$store.state.updateCount
    }
  },

  watch: {
    updateCount() {
      this.currentTab.componentName = this.tabs[0].componentName
      this.currentTab.label = this.tabs[0].label
    },
  },

  methods: {
    changeTab(tab) {
      this.currentTab.componentName = tab.componentName
      this.currentTab.label = tab.label
    },
    saveGame() {
      this.$game.save().then(() => {
        this.$Message.info('游戏已存档')
      })
    },
  },
}
</script>

<style lang="scss">

</style>
